package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.HotWord;
import com.ruoyi.system.domain.Job;
import com.ruoyi.system.service.IHotWordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 热词统计Controller
 * 
 * @author ruoyi
 * @date 2024-06-27
 */
@RestController
@RequestMapping("/system/word")
public class HotWordController extends BaseController
{
    @Autowired
    private IHotWordService hotWordService;

    /**
     * 查询热词列表
     */

    @GetMapping("/list")
    public TableDataInfo list(HotWord hotWord)
    {
        startPage();
        List<HotWord> list = hotWordService.selectHotWordList(hotWord);
        return getDataTable(list);
    }

    @GetMapping("/listBy")
    public TableDataInfo listBy(String word)
    {
        HotWord hotWord = new HotWord();
        hotWord.setWord(word);
        
        List<HotWord> list = hotWordService.selectHotWordList(hotWord);
        return getDataTable(list);
    }
    /**
     * 导出热词统计列表
     */
    @PreAuthorize("@ss.hasPermi('system:word:export')")

    @PostMapping("/export")
    public void export(HttpServletResponse response, HotWord hotWord)
    {
        List<HotWord> list = hotWordService.selectHotWordList(hotWord);
        ExcelUtil<HotWord> util = new ExcelUtil<HotWord>(HotWord.class);
        util.exportExcel(response, list, "热词统计数据");
    }

    /**
     * 获取热词统计详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:word:query')")
    @GetMapping(value = "/{hotId}")
    public AjaxResult getInfo(@PathVariable("hotId") Long hotId)
    {
        return success(hotWordService.selectHotWordByHotId(hotId));
    }

    /**
     * 新增热词统计
     */

    @PostMapping
    public AjaxResult add(@RequestBody HotWord hotWord)
    {
        return toAjax(hotWordService.insertHotWord(hotWord));
    }

    /**
     * 修改热词统计
     */

    @PutMapping
    public AjaxResult edit(@RequestBody HotWord hotWord)
    {
        return toAjax(hotWordService.updateHotWord(hotWord));
    }

    /**
     * 删除热词统计
     */
    @PreAuthorize("@ss.hasPermi('system:word:remove')")

	@DeleteMapping("/{hotIds}")
    public AjaxResult remove(@PathVariable Long[] hotIds)
    {
        return toAjax(hotWordService.deleteHotWordByHotIds(hotIds));
    }

    /**
     * 查找出num最高的4个热词
     */
    @GetMapping("/listTopFour")
    public AjaxResult listTopFour() {
        List<HotWord> topHotWords = hotWordService.selectTopHotWords(4);
        return AjaxResult.success(topHotWords);
    }
}
